﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EDiamondModel;

public partial class Admin_LoaiSanPhamThem : System.Web.UI.Page
{
    EDiamondEntities1 db = new EDiamondEntities1();
    void LoadMaNhaSanXuat()
    {
        ddlMaNSX.DataValueField = "MaNhaSanXuat";
        ddlMaNSX.DataTextField = "TenNhaSanXuat";
        ddlMaNSX.DataSource = db.NhaSanXuats;
        ddlMaNSX.DataBind();

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadMaNhaSanXuat();
    }
    protected void btnGhiNhan_Click(object sender, EventArgs e)
    {
        string ten = txtTenLSP.Text.Trim();
        string ma = ddlMaNSX.SelectedValue;
        if (txtTenLSP.Text == "")
            return;
        int d = db.LoaiSanPhams.Count(p => p.TenLoai == ten);
        if (d == 0)
        {
            LoaiSanPham lsp = new LoaiSanPham();
            lsp.TenLoai = ten;
            lsp.BiDanh = Thuvien.BoDauTiengViet(txtTenLSP.Text.Trim());
            lsp.MaNhaSanXuat = Int32.Parse(ma);

            db.LoaiSanPhams.AddObject(lsp);
            db.SaveChanges();
            lbThongBao.Text = "Thêm thành công!";

        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('loại sản phẩm đã có rồi!');", true);
        }
    }
}